package com.bpmn.system.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.bpmn.common.annotation.ResponseInfoWrapper;
import com.bpmn.system.domain.form.LoginForm;
import com.bpmn.system.domain.vo.LoginVo;
import com.bpmn.system.domain.vo.UserInfo;
import com.bpmn.system.service.AuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author rain
 */
@Tag(name = "认证管理")
@RestController
@RequiredArgsConstructor
@ResponseInfoWrapper
@RequestMapping("/auth")
public class AuthController {

    private final AuthService authService;

    @Operation(summary = "登录")
    @PostMapping("/login")
    public LoginVo login(@Validated @RequestBody LoginForm form) {
        return authService.login(form);
    }

    @Operation(summary = "退出登录")
    @PostMapping("/logout")
    public Boolean logout() {
        StpUtil.logout();
        return true;
    }

    @Operation(summary = "获取用户信息")
    @GetMapping("/info")
    public UserInfo getInfo() {
        return authService.getUserInfo();
    }
} 